Skip to main content
ICT
Lesson A6 - Libraries and APIs
 
Main Previous
Title Page >  
Summary >  
Lesson A1 >  
Lesson A2 >  
Lesson A3 >  
Lesson A4 >  
Lesson A5 >  
Lesson A6 >  
Lesson A7 >  
Lesson A8 >  
Lesson A9 >  
Lesson A10 >  
Lesson A11 >  
Lesson A12 >  
Lesson A13 >  
Lesson A14 >  
Lesson A15 >  
Lesson A16 >  
Lesson A17 >  
Lesson A18 >  
Lesson A19 >  
Lesson A20 >  
Lesson A21 >  
Lesson A22 >  
Lesson AB23 >  
Lesson AB24 >  
Lesson AB25 >  
Lesson AB26 >  
Lesson AB27 >  
Lesson AB28 >  
Lesson AB29 >  
Lesson AB30 >  
Lesson AB31 >  
Lesson AB32 >  
Lesson AB33 >  
Vocabulary >  
 

LAB ASSIGNMENT A6.2 page 12 of 12

RegularPolygon

Background:

Polygons are two-dimensional shapes formed by line segments. The segments are edges that meet in pairs at corners called vertices. A polygon is regular if all its sides are equal and all its angles are equal.

For an n-sided regular polygon of side s, the angle at any vertex is q, and the radii of the inscribed and circumscribed circles are r and R respectively. A 5-sided regular polygon (pentagon) would be represented as follows:

Assignment:

  1. Create a RegularPolygon class to model any regular polygon. Use the following declarations as a starting point for your lab work.

  1. Write two constructor methods. The default constructor creates a 3-sided polygon (triangle). The other constructor takes an integer value representing the number of sides and a double value representing the length of the sides and constructs the corresponding regular polygon.

  2. Write a method that calculates the vertex angle, q. This angle can be determined as follows:

    where n represents the number of sides.

  3. Write a method that calculates the perimeter. This value is determined simply as the number of sides, n, times the length of a side, s:

  4. Write a method that calculates the radius of the inscribed circle, r. The inscribed circle is the circle that can be drawn inside of the regular polygon such that it is tangent to every side of the polygon, for example, the smaller circle in the diagram above. It can be calculated as:

where n represents the number of sides, s represents the length of a side, and cot() is the trigonometric function, cotangent. We use the value π instead of 180 in the formula because the Java math functions assume that angles are given in radians instead of degrees. Note: the built-in Java method math.PI produces the value of π. An alternative is to replace π with 180 in all the formulas here and use following method from the Math Class to convert from degrees to radians:

    Math.toRadians(double angdeg)

The cotangent function is not part of the Java Math library, however, the cotangent of an angle can be calculated as the reciprocal of the tangent as follows:

  1. Write a method that calculates the radius of the circumscribed circle, R. The circumscribed circle is the circle that intersects each vertex of the polygon, for example the larger circle in the diagram above. R can be calculated as:

    where n represents the number of sides, s represents the length of a side and csc() is the trigonometric function, cosecant. The cosecant function is not part of the Java Math Class, however, the cosecant of an angle can be calculated as the reciprocal of the sine as follows:

  2. Write a method that calculates the area of the regular polygon. It can be calculated as:

    where n represents the number of sides and R represents the radius of the circumscribed circle.

  3. All trigonometric function in the Java Math Class take radians as the parameter. To convert an angle measured in degrees to the equivalent angle measured in radians use the following method from the Math Class:

    public static double toRadians(double angdeg)

Instructions:

  1. Test the default constructor by constructing a regular polygon with no parameters as follows:

    RegularPolygon poly = new RegularPolygon();

  2. Use the following values to test your functions:

Square: number of sides = 4, length of side = 10
Octagon: number of sides = 8, length of side = 5.75
Enneadecagon: number of sides = 19, length of side = 2
Enneacontakaihenagon: number of sides = 91, length of side = 0.5

Answers:

 

Main Previous
Contact
 © ICT 2006, All Rights Reserved.